/*
 * Copyright 2018 The Kubernetes Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

@import 'mixins';
@import 'sizing';
@import '../common/narrow-window';
@import '../Card/mixins';

@mixin full-width-tables {
  .kui--data-table-wrapper:not(.kui--data-table-as-grid) {
    /* render tables full-width when sidecar is open https://github.com/IBM/kui/issues/3952 */
    &,
    .kui--card {
      flex: 1;
    }
  }
  .kui--paginated-table {
    flex: 1;
  }

  .repl-result {
    width: 100%;
  }

  [data-table-watching]:not([data-table-as-grid='true']) {
    width: 100%;
  }

  .bx--data-table-container {
    width: 100%;
    .bx--data-table {
      width: 100%;

      /* td.entity-name,
      td.kui--entity-name-secondary {
        width: 100%;
        max-width: 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      } */
    }
  }
}

@mixin full-width-tables-with-constrained-width {
  @include full-width-tables;
  .hide-with-sidecar {
    display: none;
  }
}

@include narrow-window {
  @include full-width-tables-with-constrained-width;
}
.kui--scrollback div[data-table-watching] {
  @include full-width-tables;
}

.kui--scrollback {
  &:not([data-is-width-constrained]) .kui--data-table-container {
    div[data-table-watching] {
      min-width: calc(1.5 * #{$min-body-width});
    }
  }
}

@include Table {
  @include CardFooterNotEmpty {
    border-top: 1px solid var(--color-base03);
  }
}

body[kui-theme-style] {
  @include TableOuter {
    /* overflow-x: auto; */

    .kui--table-like-wrapper p {
      margin: 0;
    }

    .kui--screenshotable {
      flex: 1;
      display: flex;
    }

    @include CardFooter {
      padding: 0;
      .kui--data-table-toolbar-bottom {
        padding-left: var(--pf-c-card--child--PaddingLeft);
        padding-right: var(--pf-c-card--child--PaddingRight);
      }
    }

    @include CardBody {
      table {
        td,
        th {
          padding-left: var(--pf-c-card--child--PaddingLeft);
        }

        td {
          h2 {
            margin: 0;
          }
        }
      }

      .pf-m-wrap {
        word-break: break-all;
      }
    }

    &:not(.kui--data-table-as-grid) {
      .kui--card-body {
        padding-top: 0;
        padding-left: 0;
        padding-right: 0;
        padding-bottom: 0;

        .bx--data-table-container {
          padding-top: 0;
        }
      }
    }
  }
}

.kui--paginated-table {
  display: flex;
  flex-direction: column;
}

/** inner scrolling for tall tables, when not width constrained */
.kui--scrollback:not([data-is-width-constrained]) {
  .kui--data-table-container:not([data-is-empty]) {
    min-width: $min-body-width;
    /* max-height: $max-body-height; see https://github.com/IBM/kui/issues/5221 */
    min-height: $min-body-height;
  }
}

.kui--radio-table-row.kui--inverted-color-context.bx--structured-list-row--selected {
  background-color: var(--color-sidecar-header);
}

body[kui-theme-style='dark'] .kui--radio-table-row.kui--inverted-color-context.bx--structured-list-row--selected {
  background-color: var(--color-sidecar-background);
}

@include TableCard {
  background-color: $table-background-color;
}
